# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from decimal import Decimal
from typing import Union
from fastapi import Query
from pydantic import BaseModel, Field


class BalanceSearchIn(BaseModel):
    """ 余额明细搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    type: Union[str, None] = Query(default=None, description="检索类型: [points,train,robot,know]")
    user: Union[str, None] = Query(default=None, description="用户信息")
    action: Union[str, int, None] = Query(default=None, description="变动动作:")
    change_type: Union[str, int, None] = Query(default=None, description="变动类型")
    start_time: Union[int, str, None] = Query(default=None, description="开始时间")
    end_time: Union[int, str, None] = Query(default=None, description="结束时间")


"""--------------- Separator ---------------"""


class BalanceListVo(BaseModel):
    """余额明细列表Vo """
    id: int = Field(description="文章ID")
    log_sn: str = Field(description="日志编号")
    action: int = Field(description="变动类型: [1=增加, 2=减少]")
    source_sn: str = Field(description="来源单号")
    change_type: str = Field(description="变动类型")
    change_amount: Decimal = Field(description="变动的金额")
    before_amount: Decimal = Field(description="变动前金额")
    after_amount: Decimal = Field(description="变动后金额")
    create_time: str = Field(description="创建时间")
    user: dict = Field(default="用户信息")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "log_sn": "202319254523567",
                "action": 1,
                "source_sn": "-",
                "change_type": "平台扣减余额",
                "change_amount": 0.01,
                "before_amount": 0.0,
                "after_amount": 0.0,
                "create_time": "2024-07-20 01:26:18",
                "user": {
                    "sn": "80965941",
                    "avatar": "http://0.0.0.0:8100/xiao.png",
                    "mobile": "13800138000",
                    "nickname": "xiao"
                }
            }
        }
